package com.bingquan.company.stream;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {

    /**
     * +--------------------+       +------+   +------+   +---+   +-------+
     * | stream of elements +-----> |filter+-> |sorted+-> |map+-> |collect|
     * +--------------------+       +------+   +------+   +---+   +-------+
     * stream  里两个操作：
     *  1、中间操作  intermediate operation
     *  2、终止操作  terminal operation
     *
     * @param args
     */
    public static void main(String[] args) {
        Stream<String> stream = Stream.of("黄药师", "冯蘅", "郭靖", "黄蓉", "郭芙", "郭襄", "郭破虏");
        stream.filter(s -> s.startsWith("郭")).forEach(s -> System.out.println(s));
        System.out.println("=============");

        Stream<String> var = Stream.of("a", "b", "c", "d");
        List<String> collect = var.limit(3).collect(Collectors.toList());
        collect.stream().forEach(s -> System.out.println(s));
    }
}